<template>
<!--    <el-dropdown>-->
<!--      <i class="el-icon-setting" style="margin-right: 15px"></i>-->
<!--      <template #dropdown>-->
<!--        <el-dropdown-menu>-->
<!--          <el-dropdown-item>查看</el-dropdown-item>-->
<!--          <el-dropdown-item>新增</el-dropdown-item>-->
<!--          <el-dropdown-item>删除</el-dropdown-item>-->
<!--        </el-dropdown-menu>-->
<!--      </template>-->
<!--    </el-dropdown>-->
    <el-tag>{{ user.username }}</el-tag>
    <span v-show="!hasLogin"><el-link type="primary" style="width: 80px" href="#/login">登录</el-link></span>
    <span v-show="hasLogin"><el-link type="primary" style="width: 80px"  @click="logout">退出</el-link></span>
</template>

<script>
export default {
  name: "Head",
  methods: {
    logout(){
      const _this = this
      _this.axios.get("/admin/logout").then(res => {
        console.log(res)
        _this.$store.commit("removeUserInfo")
        _this.$router.push("/login")
      })
    }
  },
  data() {
    return {
      hasLogin : false,
      user : {
        username: '请登录'
      }
    }
  },
  created() {
    if (this.$store.getters.getUser != null && this.$store.getters.getUser.username) {
      this.user.username = this.$store.getters.getUser.username

      this.hasLogin = true
    }
  }
}
</script>

<style scoped>

</style>
